import { IDENX_CORE_MAP } from "../../constant/index";
import customerApi from "../../utils/customerApi";
import { throttle, throttle2, withTokenFn } from "../../utils/util";
const app = getApp();
Component({
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    className: String,
  },
  /**
   * 组件的初始数据
   */
  data: {
    subscribe: IDENX_CORE_MAP["subscribe"],
    comment: IDENX_CORE_MAP["comment"],
    question: IDENX_CORE_MAP["question"],
    consult: IDENX_CORE_MAP["consult"],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * @description: 点击疫苗体检
     */
    jumpSubscribe() {
      wx.navigateTo({
        url: "../../pages/vaccine-list/index",
      });
    },
    /**
     * @description: 点击看热评
     */
    jumpComment() {
      withTokenFn(() => {
        throttle(function () {
          wx.navigateTo({
            url: "../../pages/hot-comment/index",
          });
        }, 2000);
      });
    },

    jumpQuestion() {
      throttle(function () {
        wx.navigateTo({
          url: "../../pages/vaccine-search/index",
        });
      }, 2000);
    },

    jumpConsultByThrottle2: throttle2(function () {
      this.messageCompany();
    }, 2000),

    jumpConsult() {
      this.jumpConsultByThrottle2();
    },

    messageCompany() {
      withTokenFn(() => {
        customerApi.messageCompany({
          data: {},
          success: (res) => {
            if (res.code * 1 === 0) {
              app.globalData.customerChoose = res.data.conversation;
              throttle(function () {
                wx.navigateTo({
                  url: `../customerIntelligent/index`,
                });
              }, 2000);
            }
          },
        });
      });
    },
  },
});
